package kjj.android.widget.app;

import android.app.Activity;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import android.os.Parcelable;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

public class AndroidWidgetActivity extends Activity implements OnClickListener {
	
	private Button btnShortcut;
	private Button btnQuit;
	
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        btnQuit = (Button)findViewById(R.id.buttonQuit);
        btnShortcut	= (Button)findViewById(R.id.buttonShortcut);
        btnQuit.setOnClickListener(this);
        btnShortcut.setOnClickListener(this);
        
    }
    
    @Override
    public void onClick(View v){
    	if (v == btnQuit){
    		//quit 
    		System.exit(0);
    	}
    	else if (v == btnShortcut) {
			Intent addIntent = new Intent(
					"com.android.launcher.action.INSTALL_SHORTCUT");
			String mytitle = getResources().getString(R.string.MyTitle);
			Parcelable iconParcelable = 
				Intent.ShortcutIconResource.fromContext(this, R.drawable.plant_leaf);
			
			Intent myIntent = new Intent(this, AndroidWidgetActivity.class);
			addIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, mytitle);
			addIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, iconParcelable);
			addIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, myIntent);
			
			sendBroadcast(addIntent);			
		}
    }
}